package com.zhixing.web.common.utils;

import org.springframework.stereotype.Component;

import java.util.Random;

/**
 * @author dzh
 * @version 1.0.0.05020
 * <p>project: d-blog</p>
 * <p>created time: 2022/05/02 15:17</p>
 * <p>describe: 随机数生成工具类</p>
 * <p>remarks: </p>
 **/
@Component
public class RandomNumUtil {

    static String genRandomNum(int num) {

        String str = "0123456789";

        StringBuilder code = new StringBuilder(num);

        for (int i = 0; i < num; i++) {

            char ch = str.charAt(new Random().nextInt(str.length()));

            code.append(ch);
        }

        return code.toString();
    }
}
